package cn.echoedu.specifics;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

import cn.echoedu.daoconstants.TableName;
import cn.echoedu.entity.Degress;
import cn.echoedu.entity.Image;
import cn.echoedu.entity.Job;
import cn.echoedu.entity.PoliticalStatus;
import cn.echoedu.entity.School;
import cn.echoedu.entity.Teacher;
import cn.echoedu.util.L;

public class SpecTeacher extends BaseSpec{
	private final String T="SpecTeacher---------->";
	@Override
	public <T> PreparedStatement getPreparedInsert(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		Teacher teacher=(Teacher)currentPojo;
		String sql="insert into teacher(teachernumber," +
				"name,realname,sex,birthday,password," +
				"qq,email,baidunumber,sinanumber,wechatnumber," +
				"jobcode,schoolcode,degresscode,politicalstatuscode," +
				"headimageid) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		PreparedStatement preparedstatement=con.prepareStatement(sql);
		preparedstatement.setString(1,teacher.getTeachernumber());
		preparedstatement.setString(2,teacher.getName());
		preparedstatement.setString(3,teacher.getRealname());
		preparedstatement.setString(4,teacher.getSex());
		preparedstatement.setDate(5,(Date) teacher.getBirthday());
        preparedstatement.setString(6,teacher.getPassword());
		preparedstatement.setString(7,teacher.getQq());
		preparedstatement.setString(8,teacher.getEmail());
		preparedstatement.setString(9,teacher.getBaidunumber());
		preparedstatement.setString(10,teacher.getSinanumber());
		preparedstatement.setString(11,teacher.getWechatnumber());
		if(teacher.getJob()!=null){
			preparedstatement.setInt(12,teacher.getJob().getJobcode());
		}
		else{
			preparedstatement.setNull(12,Types.INTEGER);

		}
		if(teacher.getSchool()!=null){
			preparedstatement.setInt(13,teacher.getSchool().getSchoolcode());
		}else{
			preparedstatement.setNull(13,Types.INTEGER);
		}
		if(teacher.getDegress()!=null){
			preparedstatement.setInt(14,teacher.getDegress().getDegressid());
		}else{
			preparedstatement.setNull(14,Types.INTEGER);
		}
		if(teacher.getPoliticalstatus()!=null){
			preparedstatement.setInt(15,teacher.getPoliticalstatus().getPoliticalstatuscode());
		}
		else{
			preparedstatement.setNull(15,Types.INTEGER);
		}
		if(teacher.getImage()!=null){
			preparedstatement.setInt(16,teacher.getImage().getImageid());
		}else{
			preparedstatement.setNull(16,Types.INTEGER);
		}
	
		return preparedstatement;
	}

	@Override
	public <T> PreparedStatement getPreparedInsertRunning(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		final String M="getPreparedInsertRunning";
		L.p(T+M);
		Teacher teacher=(Teacher)currentPojo;
		String sql="insert into teacher(name,realname,sex," +
				"birthday,entrancetime,password," +
				"politicalstatuscode,examineenumber,qq,email," +
				"baidunumber,sinanumber,wechatnumber," +
				"jobcode,schoolcode,degresscode,politicalstatuscode," +
				"headimageid) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		PreparedStatement preparedstatement=con.prepareStatement(sql);
		preparedstatement.setString(1,teacher.getName());
		preparedstatement.setString(2,teacher.getRealname());
		preparedstatement.setString(3,teacher.getSex());
		preparedstatement.setDate(4,(Date) teacher.getBirthday());
		preparedstatement.setString(5,teacher.getPassword());
		preparedstatement.setString(6,teacher.getQq());
		preparedstatement.setString(7,teacher.getEmail());
		preparedstatement.setString(8,teacher.getBaidunumber());
		preparedstatement.setString(9,teacher.getSinanumber());
		preparedstatement.setString(10,teacher.getWechatnumber());
		if(teacher.getJob()!=null){
			preparedstatement.setInt(11,teacher.getJob().getJobcode());
		}
		else{
			preparedstatement.setNull(11,Types.INTEGER);

		}
		if(teacher.getSchool()!=null){
			preparedstatement.setInt(12,teacher.getSchool().getSchoolcode());
		}else{
			preparedstatement.setNull(12,Types.INTEGER);
		}
		if(teacher.getDegress()!=null){
			preparedstatement.setInt(13,teacher.getDegress().getDegressid());
		}else{
			preparedstatement.setNull(13,Types.INTEGER);
		}
		if(teacher.getPoliticalstatus()!=null){
			preparedstatement.setInt(14,teacher.getPoliticalstatus().getPoliticalstatuscode());
		}
		else{
			preparedstatement.setNull(14,Types.INTEGER);
		}
		if(teacher.getImage()!=null){
			preparedstatement.setInt(15,teacher.getImage().getImageid());
		}else{
			preparedstatement.setNull(15,Types.INTEGER);
		}
		return preparedstatement;
	}

	@Override
	public Object getPojo(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		Teacher teacher=new Teacher();
		teacher.setTeachernumber(rs.getString(1));
		teacher.setName(rs.getString(2));
		teacher.setSex(rs.getString(3));
		teacher.setBirthday(rs.getDate(4));
		teacher.setPassword(rs.getString(5));
		teacher.setQq(rs.getString(6));
		teacher.setEmail(rs.getString(7));
		teacher.setBaidunumber(rs.getString(8));
		teacher.setSinanumber(rs.getString(9));
		teacher.setWechatnumber(rs.getString(10));
		Job job=new Job();
		job.setJobcode(rs.getInt(11));
		teacher.setJob(job);
		School school=new School();
		school.setSchoolcode(rs.getInt(12));
		teacher.setSchool(school);
		Degress degress=new Degress();
		degress.setDegressid(rs.getInt(13));
		teacher.setDegress(degress);
		PoliticalStatus politicalstatus=new PoliticalStatus();
		politicalstatus.setPoliticalstatuscode(rs.getInt(14));
		teacher.setPoliticalstatus(politicalstatus);
		Image image=new Image();
		image.setImageid(rs.getInt(15));
		teacher.setImage(image);
		return teacher;
	}

	@Override
	public <T> PreparedStatement getPreparedUpdate(Connection con,
			TableName tableName, T oldPojo, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		Teacher  teacher=(Teacher)currentPojo;
		Teacher oldteacher=(Teacher)oldPojo;
		String sql="update teacher set name=?,realname=?,sex=?,birthday=?," +
				"password=?,qq=?,email=?,baidunumber=?,sinanumber=?," +
				"wechatnumber=?,jobcode=?,schoolcode=?,degresscode=?," +
				"politicalstatuscode=?,headimageid=? where teachernumber=?";
		PreparedStatement preparedstatement=con.prepareStatement(sql);
		preparedstatement.setString(1,teacher.getName());
		preparedstatement.setString(2,teacher.getRealname());
		preparedstatement.setString(3,teacher.getSex());
		preparedstatement.setDate(4,(Date) teacher.getBirthday());
		preparedstatement.setString(5,teacher.getPassword());
		preparedstatement.setString(6,teacher.getQq());
		preparedstatement.setString(7,teacher.getEmail());
		preparedstatement.setString(8,teacher.getBaidunumber());
		preparedstatement.setString(9,teacher.getSinanumber());
		preparedstatement.setString(10,teacher.getWechatnumber());
		preparedstatement.setInt(11,teacher.getJob().getJobcode());
		preparedstatement.setInt(12,teacher.getSchool().getSchoolcode());
		preparedstatement.setInt(13,teacher.getDegress().getDegressid());
		preparedstatement.setInt(14,teacher.getPoliticalstatus().getPoliticalstatuscode());
		preparedstatement.setInt(15,teacher.getImage().getImageid());
		preparedstatement.setString(16,oldteacher.getTeachernumber());
		return preparedstatement;
	}

	@Override
	public Object getLeftJoinPojo(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object getPojoBySql(ResultSet rs) throws SQLException {
		// TODO Auto-generated method stub
		Teacher teacher = new Teacher();
		teacher.setTeachernumber(rs.getString("teacher.teachernumber"));
		teacher.setName(rs.getString("teacher.name"));
		teacher.setRealname(rs.getString("teacher.name"));
		teacher.setSex(rs.getString("teacher.sex"));
		teacher.setBirthday(rs.getDate("teacher.birthday"));
		teacher.setPassword(rs.getString("teacher.password"));
		teacher.setQq(rs.getString("teacher.qq"));
		teacher.setEmail(rs.getString("teacher.email"));
		teacher.setBaidunumber(rs.getString("teacher.baidunumber"));
		teacher.setSinanumber(rs.getString("teacher.sinanumber"));
		teacher.setWechatnumber(rs.getString("teacher.wechatnumber"));
		Job job = new Job();
		job.setJobcode(rs.getInt("job.jobcode"));
		job.setJobname(rs.getString("job.jobname"));
		teacher.setJob(job);
		School school = new School();
		school.setSchoolcode(rs.getInt("school.schoolcode"));
		school.setSchoolname(rs.getString("school.name"));
		teacher.setSchool(school);
		Degress degress = new Degress();
		degress.setDegressid(rs.getInt("degress.degressid"));
		degress.setDegressname(rs.getString("degress.degressname"));
		degress.setContent(rs.getString("degress.content"));
		teacher.setDegress(degress);
		PoliticalStatus politicalstatus = new PoliticalStatus();
		politicalstatus.setPoliticalstatuscode(rs.getInt("politicalstatus.politicalstatuscode"));
		politicalstatus.setPoliticalstatusname(rs.getString("politicalstatus.politicalstatusname"));
		politicalstatus.setDescription(rs.getString("politicalstatus.description"));
		teacher.setPoliticalstatus(politicalstatus);
		Image image = new Image();
		image.setImageid(rs.getInt("image.imageid"));
		image.setImagename(rs.getString("image.imagename"));
		image.setImagesrc(rs.getString("image.imagesrc"));
		teacher.setImage(image);
		return teacher;
	}

	@Override
	public <T> String getPreparedInsertGetPrimaryKeySql(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> PreparedStatement getPreparedListInsert(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> PreparedStatement getPreparedListInsertRunning(Connection con,
			TableName tableName, T currentPojo) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

}
